package Jisuanqi;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import java.io.IOException;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.UIManager;

public class Login_Interface extends JFrame {

    private static final long serialVersionUID = 1L;  //定义程序序列化,1L是默认定义

    protected static String s1;
    protected static String s2;
    protected static String s3;

    private JLabel jl1 = new JLabel("欢迎来到考试系统");
    private JLabel jl2 = new JLabel("请填写下列信息");
    private JLabel jl3 = new JLabel("    ");
    private JLabel jl4 = new JLabel("        ");

    private JLabel JLName = new JLabel("姓名：");
    private JLabel JLMagic = new JLabel("专业：");
    private JLabel JLClass = new JLabel("班级：");

    private JTextField JTName = new JTextField(10);
    private JTextField JTMagic = new JTextField(10);
    private JTextField JTClass = new JTextField(10);

    private JButton JB1 = new JButton("开始考试");
    private JButton JB2 = new JButton("重置");
    private JButton JBave = new JButton("平均分查看");

    private JPanel jp1 = new JPanel();
    private JPanel jp2 = new JPanel();
    private JPanel jp3 = new JPanel();
    private JPanel jp4 = new JPanel();
    private JPanel jp5 = new JPanel();
    private JPanel jp6 = new JPanel();
    private JPanel jp7 = new JPanel();

    private void Event() {

        JB1.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if(JTName.getText().equals("") || JTClass.getText().equals("") || JTMagic.getText().equals("")) {
                    String s = "请输入完整信息";
                    JOptionPane.showMessageDialog(null, s,"提示",JOptionPane.ERROR_MESSAGE);

                }else {
                    setVisible(false);
                    dispose();
                    s1 = JTName.getText();
                    s2 = JTClass.getText();
                    s3 = JTMagic.getText();
                    new Test_Interface();
                }
            }
        });
        JB2.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                JTName.setText(null);
                JTMagic.setText(null);
                JTClass.setText(null);
            }
        });
        JBave.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                try {
                    new Average_Score();
                } catch (IOException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                }
            }
        });
    }


    public Login_Interface() {

        this.setTitle("口算练习器界面");
        this.setSize(500, 450);
        this.setLocationRelativeTo(null);  //将此窗口置于屏幕的中央
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setLayout(new BorderLayout(20,20));

        jl1.setFont(new Font("黑体",Font.BOLD,35));
        jl1.setForeground(Color.blue);
        jp1.add(jl1);
        jp1.setLayout(new GridBagLayout());
        this.add(jp1,BorderLayout.NORTH);

        jl2.setFont(new Font("黑体",Font.BOLD,25));
        jl2.setForeground(Color.red);
        jp2.add(jl2);

        JLName.setFont(new Font("黑体",Font.BOLD,15));
        jp3.add(JLName);
        jp3.add(JTName);

        JLMagic.setFont(new Font("黑体",Font.BOLD,15));
        jp4.add(JLMagic);
        jp4.add(JTMagic);

        JLClass.setFont(new Font("黑体",Font.BOLD,15));
        jp5.add(JLClass);
        jp5.add(JTClass);

        jp6.add(jp2);
        jp6.add(jp3);
        jp6.add(jp4);
        jp6.add(jp5);
        jp6.setLayout(new GridLayout(4,2));
        this.add(jp6,BorderLayout.CENTER);
        jp6.setBorder(BorderFactory.createLoweredBevelBorder());

        jp7.add(JBave);
        jp7.add(jl4);
        jp7.add(JB1);
        jp7.add(jl3);
        jp7.add(JB2);
        this.add(jp7,BorderLayout.SOUTH);

        //美化界面
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (Exception e) {
            e.printStackTrace();
        }

        Event();

        this.setVisible(true);
    }

    public static void main(String[] args) {

        new Login_Interface();
    }
}


